package com.chencs.common.lmadmin.controller;

import com.alibaba.fastjson.JSON;
import com.chencs.common.lmadmin.service.LmProductService;
import com.chencs.vo.biz.lianmeng.LmCategory;
import com.chencs.vo.biz.lianmeng.LmCategory_item;
import com.chencs.vo.biz.lianmeng.LmProduct;
import com.chencs.vo.net.response.ResponseBase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/m/lmProduct")
public class LmProductController {

    /**
     *
     */


    @Autowired
    private LmProductService productService;

    @RequestMapping(value = "/getList", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String productList() {
        List<LmProduct> productList = productService.getProductList();
        return JSON.toJSON(productList).toString();
    }


    @RequestMapping(value = "/getCategoryList", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String getCategoryList() {
        List<LmCategory> category = productService.getLmCategory();
        return JSON.toJSON(category).toString();
    }


    @RequestMapping(value = "/getLmCategoryItem", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String getLmCategoryItem(@RequestBody String cid) {
        List<LmCategory_item> categoryItem = productService.getLmCategoryItem(cid);
        return JSON.toJSON(categoryItem).toString();
    }


    @RequestMapping(value = "/findLmCategory", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String findLmCategory(@RequestBody String id) {
        LmCategory category = productService.findLmCategory(id);
        return JSON.toJSON(category).toString();
    }



    @RequestMapping(value = "/insertLmCategory", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String insertLmCategory(@RequestBody LmCategory category) {
        ResponseBase  response = new ResponseBase();
         productService.insertLmCategory(category);
        return JSON.toJSON(response).toString();
    }

    @RequestMapping(value = "/updateLmCategory", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String updateLmCategory(@RequestBody LmCategory category) {
        ResponseBase  response = new ResponseBase();
        productService.updateLmCategory(category);
        return JSON.toJSON(response).toString();
    }




    @RequestMapping(value = "/findLmCategory_item", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String findLmCategory_item(@RequestBody String id) {
        ResponseBase  response = new ResponseBase();
        LmCategory_item category_item = productService.findLmCategory_item(id);
        return JSON.toJSON(response).toString();
    }


    @RequestMapping(value = "/insertLmCategory_item", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String insertLmCategory_item(@RequestBody LmCategory_item category) {
        ResponseBase  response = new ResponseBase();
        productService.insertLmCategory_item(category);
        return JSON.toJSON(response).toString();
    }

    @RequestMapping(value = "/updateLmCategory_item", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String updateLmCategory(@RequestBody LmCategory_item category) {
        ResponseBase  response = new ResponseBase();
        productService.updateLmCategory_item(category);
        return JSON.toJSON(response).toString();
    }



}
